class Stack {
  constructor (n) {
    this.arr = new Array(n);
    this.top = -1;
  }
}
Stack.prototype.push = function (value) {
  this.arr[++this.top] = value;
}

Stack.prototype.pop = function () {
  if (this.empty()) return;
  return this.arr[this.top--];
}
// 查看栈顶元素
Stack.prototype.peek = function () {
  if (this.empty()) return;
  return this.arr[this.top];
}

Stack.prototype.empty = function () {
  return this.top === -1;
}

Stack.prototype.size = function () {
  return this.top + 1;
}
Stack.prototype.output = function () {
  let ret = '';
  for (let i = this.top; i >= 0; i--) {
    ret += `${this.arr[i]},`;
  }
  console.log(ret);
}

function test() {
  let stack = new Stack(4);
  debugger;
  stack.push(1);
  stack.push(2);
  stack.pop();
  stack.push(3);
  stack.push(4);
  stack.push(5);
  stack.push(6);
  stack.output();
}
test();